/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel.grid;

import org.rails.extjs.javascript.Function;

public class GroupingView extends GridView {

	public GroupingView() {
		super();
	}
	
	public void setEmptyGroupText(String emptyGroupText){
		addOption("emptyGroupText", emptyGroupText);
	}
	
	public String getEmptyGroupText(){
		return getString("emptyGroupText", "(None)");
	}
	
	public void setEnableGrouping(Boolean enableGrouping){
		addOption("enableGrouping", enableGrouping);
	}
	
	public Boolean isEnableGrouping(){
		return getBoolean("enableGrouping", true);
	}
	
	public void setEnableGroupingMenu(Boolean enableGroupingMenu){
		addOption("enableGroupingMenu", enableGroupingMenu);
	}
	
	public Boolean isEnableGroupingMenu(){
		return getBoolean("enableGroupingMenu", true);
	}
	
	public void setEnableNoGroups(Boolean enableNoGroups){
		addOption("enableNoGroups", enableNoGroups);
	}
	
	public Boolean isEnableNoGroups(){
		return getBoolean("enableNoGroups", true);
	}
	
	public void setGroupByText(String groupByText){
		addOption("groupByText", groupByText);
	}
	
	public String getGroupByText(){
		return getString("groupByText", "Group By This Field");
	}
	
	public void setGroupMode(String groupMode){
		addOption("groupMode", groupMode);
	}
	
	public String getGroupMode(){
		return getString("groupMode", "value");
	}
	
	public void setGroupRenderer(Function groupRenderer){
		addOption("groupRenderer", groupRenderer);
	}
	
	public Function getGroupRenderer(){
		return (Function)getOption("groupRenderer");
	}
	
	public void setGroupTextTpl(String groupTextTpl){
		addOption("groupTextTpl", groupTextTpl);
	}
	
	public String getGroupTextTpl(){
		return getString("groupTextTpl", "{text}");
	}
	
	public void setHideGroupedColumn(Boolean hideGroupedColumn){
		addOption("hideGroupedColumn",hideGroupedColumn);
	}
	
	public Boolean isHideGroupedColumn(){
		return getBoolean("hideGroupedColumn",false);
	}
	
	public void setIgnoreAdd(Boolean ignoreAdd){
		addOption("ignoreAdd", ignoreAdd);
	}
	
	public Boolean isIgnoreAdd(){
		return getBoolean("ignoreAdd", false);
	}
	
	public void setShowGroupName(Boolean showGroupName){
		addOption("showGroupName", showGroupName);
	}
	
	public Boolean isShowGroupName(){
		return getBoolean("showGroupName", true);
	}
	
	public void setShowGroupsText(String showGroupsText){
		addOption("showGroupsText", showGroupsText);
	}
	
	public String getShowGroupsText(){
		return getString("showGroupsText","Show in Groups");
	}
	
	public void setStartCollapsed(Boolean startCollapsed){
		addOption("startCollapsed", startCollapsed);
	}
	
	public Boolean isStartCollapsed(){
		return getBoolean("startCollapsed", false);
	}

	@Override
	public String getScript() {
		createItems();
		script = new StringBuffer("");
		script.append("new Ext.grid.GroupingView(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}	
}
